package com.finance.system.bean.pojo;

import com.finance.framework.lang.BaseObject;
import com.finance.framework.lang.TreeNode;
import lombok.Data;
import org.springframework.stereotype.Component;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by CBWL on 2017/3/17.
 */
@Data
@Component
public class Menu extends BaseObject implements Serializable,TreeNode{
    private String name;//菜单名称
    private String url;//请求路径
    private String code;//菜单code
    private String pCode;//父级code
    private Integer type;//类型
    private Integer sort;//顺序
    private boolean checked;// 选中状态
    private List<Menu> children;//子级菜单

    @Override
    public List<Menu> getChildren() {
        return children;
    }

    @Override
    public void append(TreeNode node) {
        Menu menu = (Menu) node;
        if(this.children==null){
            this.children = new ArrayList<Menu>();
        }
        this.children.add(menu);
    }

    @Override
    public void remove(TreeNode node) {
        this.children.remove(node);
    }

    @Override
    public boolean equals(Object object) {
        if (object instanceof Menu) {
            Menu menu = (Menu) object;
            return menu.getCode().equals(this.code);
        }
        return false;
    }

    @Override
    public int hashCode() {
        return this.getCode().hashCode();
    }

}